package mybatisPlugin.dao;

import mybatisPlugin.entity.Player;
import mybatisPlugin.entity.Team;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author caihe
 * @date 2022/12/16 19:34
 */
public interface TeamDao {
    @Select("SELECT * FROM team")
    @Results(value = {
            @Result(property = "teamId", column = "teamId", id = true),
            @Result(property = "name", column = "name"),
            @Result(property = "players", column = "teamId", many = @Many(select = "selectPlayers"))
    })
    public List<Team> getAllTeams();

    @Select("SELECT * FROM player WHERE teamId = #{teamId}")
    @Results(value = {
            @Result(property = "playerId", column = "playerId", id = true),
            @Result(property = "name", column = "name")
    })
    List<Player> selectPlayers(String teamId);
}
